<?php
require_once __DIR__ . '/../autoload.php';

use  src\DataBase;

/**
 * 处理cms首页静态化业务逻辑
 * 有3种方案， 第一：定时(利用crontab来处理)  第二：人为触发 第三：在页面中控制时间来操作
 */
//header("content-type:text/htm;charset=utf-8");  300s

if (is_file('./staticPage/inquire.html') && (time() - filemtime('./staticPage/inquire.html') < 0.1)) {    //触发静态页面的生成
    require_once('./staticPage/inquire.html');
} else {
    $username = $_COOKIE['school']['username'];
    $db = new DataBase\DataBaseOperate('139.196.124.180', 'school', 'user1', 'Mcx857264', 'utf8');
    $selectResult = $db->select('courseSelectionRecord', '*', array('studentInfo' => $username,'isCancel' => 0), 'insertTime', 1);
    $inquireResult = $selectResult;
    ob_start();
    require_once('./template/inquire.php');  //还是一个动态页面(localhost/staticpage/index.php)
    $s = ob_get_contents();
    file_put_contents('./staticPage/inquire.html', $s);

    //ob_clean();
}
